package ManageStudent;
import java.util.Scanner;
public class crud extends Student{
    Scanner input=new Scanner(System.in);
    int i=0;
    Student stu[]=new Student[10];

    public crud(String sid, String name, int age, String address) {
        super(sid, name, age, address);
    }

    public crud() {
    }

    public void all(){
        all:while(true){
            show();
            int a=input.nextInt();
            switch(a){
                case 1:
                    add();
                    i++;
                    break;
                case 2:
                    delete();
                    break;
                case 3:
                    gai();
                    break;
                case 4:
                    cha();
                    break;
                default:
                    System.out.println("退出系统");
                    break all;
            }

        }
            }
public void show(){
    System.out.println("--------欢迎来到学生管理系统--------");
    System.out.println("1 添加学生");
    System.out.println("2 删除学生");
    System.out.println("3 修改学生");
    System.out.println("4 查看学生");
    System.out.println("5 退出");
    System.out.println("请输入您的选择:");
    }

public void add(){
    System.out.println("请输入学生学号");
    String sid=input.next();
    System.out.println("请输入学生姓名");
    String name=input.next();
    System.out.println("请输入学生年龄");
    int age=input.nextInt();
    System.out.println("请输入学生住址");
    String address=input.next();
    Student xin=new Student(sid,name,age,address);
    stu[i]=xin;
    System.out.println("添加学生成功");
    }

    public void cha(){
        for(int j=0;j<i;j++){
            System.out.println(stu[j].sid+stu[j].name+stu[j].age+stu[j].address);
        }
    }

    public void delete(){
        System.out.println("请输入你要删除学生的学号");
        String c=input.next();
        for(int h=0;h<i;h++){
            if(c.equals(stu[h].sid)){
                Student s=new Student();
                stu[h]=s;
            }
        }
    }

    public void gai(){
        System.out.println("请输入你要修改的学生的学号：");
        String newSid=input.next();
        System.out.println("请输入学生新名称：");
        String newName=input.next();
        System.out.println("请输入学生新年龄");
        int newAge=input.nextInt();
        System.out.println("请输入学生新住址：");
        String newAdrress=input.next();
        //封装
        Student g=new Student(newSid,newName,newAge,newAdrress);
        for(int j=0;j<i;j++){
            if(newSid.equals(stu[j])){
                stu[j]=g;
            }
        }
    }
}
